package com.banquetmanagementsystem.mapper;

import com.banquetmanagementsystem.pojo.entity.Bill;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author tanghaihua
 */
@Mapper
public interface BillMapper {
    /**
     * 添加订单
     *
     * @param bill 订单信息
     * @return 受影响条数
     */
    @Insert("INSERT INTO bill(user_id, transaction_type_id, payment_method_id, transaction_amount) VALUES (#{userId},#{transactionTypeId},#{paymentMethodId},#{transactionAmount})")
    Integer insertBill(Bill bill);

    /**
     * 根据id,用户id删除订单
     *
     * @param id     订单id
     * @param userId 用户id
     * @return 受影响条数
     */
    @Delete("DELETE FROM bill WHERE id = #{id} AND user_id = #{userId}")
    Integer deleteBillByIdAndUserId(Integer id, Integer userId);

    /**
     * 根据用户id查询订单
     *
     * @param userId 用户id
     * @return 用户所有订单
     */
    @Select("SELECT id, user_id, transaction_type_id, payment_method_id, transaction_amount FROM bill WHERE user_id = #{userId}")
    List<Bill> selectBillByUserId(Integer userId);

    /**
     * 根据订单id，用户id查询订单
     *
     * @param id     订单id
     * @param userId 用户id
     * @return 订单
     */
    @Select("SELECT id, user_id, transaction_type_id, payment_method_id, transaction_amount FROM bill WHERE id = #{id} AND user_id = #{userId}")
    Bill selectBillByIdAndUserId(Integer id, Integer userId);
}
